/*
 * NESState.h
 *
 *  Created on: Oct 27, 2012
 *      Author: nam20485
 */

#ifndef NESSTATE_H_
#define NESSTATE_H_

#ifdef _GAMEPADREPORT
#include "gamepadreport.h"
#endif	// def _GAMEPADREPORT

class NESState
{
public:
	enum BUTTON
	{
		A		= 1 << 0,
		B		= 1 << 1,
		UP		= 1 << 2,
		DOWN	= 1 << 3,
		LEFT	= 1 << 4,
		RIGHT	= 1 << 5,
		SELECT	= 1 << 6,
		START	= 1 << 7,
	};

	NESState(int dataPin, int latchPin, int clockPin)
		: m_state(0)
		, DATA_PIN(dataPin)
		, LATCH_PIN(latchPin)
		, CLOCK_PIN(clockPin)
	{
		initialize();
	}

	virtual ~NESState()	{}

	virtual bool refresh();
	inline bool buttonIsPressed(BUTTON button) const	{ return (m_state & button); }

#ifdef _GAMEPADREPORT
	void createGamepadReport(USB_GamepadReport_Data_t& gamepadReport) const;
#endif	// def _GAMEPADREPORT

protected:
	int m_state;

	const int DATA_PIN;
	const int LATCH_PIN;
	const int CLOCK_PIN;

	virtual void initialize()	;
	bool inline readNextBit() const;

};

#endif /* NESSTATE_H_ */
